export function getQueryParam(url: string, param: string): string | null {
  const queryString = url.split('?')[1]
  if (!queryString)
    return null

  const params = new URLSearchParams(queryString)
  return params.get(param)
}

export const mergeData = (data: Record<string, any>): Record<string, any> => {
  const result: Record<string, any> = {}

  Object.values(data).forEach((item) => {
    Object.keys(item).forEach((key) => {
      if (!result[key]) {
        result[key] = item[key] // 初始化
      }
      else if (typeof result[key] === 'object' && !Array.isArray(result[key])) {
        // 如果是对象，合并属性
        result[key] = { ...result[key], ...item[key] }
      }
      else if (Array.isArray(result[key]) && Array.isArray(item[key])) {
        // 如果是数组，合并数组
        result[key] = [...result[key], ...item[key]]
      }
    })
  })

  return result
}
